// 验证数据
export function validateConditions(value, isNeedLeft) {
  value.forEach((item) => {
    if (!item.junction_type) {
      throw '请设置规则';
    }
    if (isNeedLeft && (!item.left_var_code || !item.left_var_type)) {
      throw '请设置条件左变量';
    }

    item.operator = getOperator(item.operator);
    if (item.operator.type !== 1) {
      if (item.right_var_code === undefined || item.right_var_code === '' || !item.right_var_type) {
        throw '请设置条件右变量';
      }
    } else {
      delete item.right_var_code;
      delete item.right_var_name;
      delete item.right_var_type;
    }
  });
  return value;
}

/**
 * @method getOperator
 * @description 获取操作符json
 */
function getOperator(value) {
  if (!value) {
    throw '请选择条件操作符';
  }
  if (Object.keys(value).length === 0) {
    throw '请选择条件操作符';
  }
  if (!value.operator || !value.symbol) {
    throw '请选择条件操作符';
  }
  return value;
}
